package com.neusoft.service.impl;

import com.neusoft.service.BotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.neusoft.service.BotService;

@Service
public class BotServiceImpl implements BotService {

	@Override
	public String listOptionByAdj(String adj) {
		System.out.println(adj);
		Process proc;
		List<String> list = new ArrayList();
		try {
			String pythonPath = "D:\\conda\\python.exe";
			String pythonFilePath = "D:\\project\\elm-spring-cloud\\elm-spring-cloud\\gpt_api/test.py";
			String[] args1 = new String[] { pythonPath, pythonFilePath, adj};
			System.out.println("step1");
			proc = Runtime.getRuntime().exec(args1);

			System.out.println("step2");


			BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(), "UTF-8"));
			String line = null;
			while ((line = in.readLine()) != null) {
				System.out.println(line);
				list.add(line);
			}
			in.close();
			int r=proc.waitFor();
			System.out.println(r);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(list);
		String res="";
		for(String c:list) {
			res+=c;
		}
		return res;
	}



}